package com.yh.dp.principle.ocp;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @ClassName BookStore
 * @Description 假书店
 * @Author 0715-YuHao
 * @Date 2021/1/2 14:56
 */
public class FakeBookStore {

    //图书集合
    private static ArrayList<IBook> bookList;

   /* static {
        bookList.add(new OffNovelBook("红楼梦", 9900, "曹雪芹 "));
        bookList.add(new OffNovelBook("侠客行", 8900, "金庸 "));
        bookList.add(new OffNovelBook("原则", 6900, "瑞·达利欧"));
        bookList.add(new OffNovelBook("海贼王1", 4900, "尾田荣一郎"));
    }*/

    public static void main(String[] args) {
        try {
            Class<?> fakeBookStore = Class.forName("com.yh.dp.principle.ocp.BookStore");
            Field bookList = fakeBookStore.getDeclaredField("bookList");
            bookList.setAccessible(true);
            Field modifiers = bookList.getClass().getDeclaredField("modifiers");
            modifiers.setAccessible(true);
            modifiers.set(bookList, bookList.getModifiers() & ~Modifier.FINAL);
            List<IBook> list = new ArrayList<>();
            list.add(new NovelBook("红楼梦", 10000, "曹雪芹1"));
            bookList.set(new BookStore(), list);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
